<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>pop和shift的实现</title>
</head>

<body>
    <script>
        // pop的实现
        Array.prototype.myPop = function () {
            let tailEle = this[this.length - 1];
            this.length--;
            return tailEle;
        }
        // shift的实现
        Array.prototype.myShift = function () {
            let headEle = this[0];
            for (let i = 1; i < this.length; i++) {
                this[i - 1] = this[i]
            }
            this.length--;
            return headEle;
        }
        let arr = [1, 2, 3];
        let tailEle = arr.myPop();
        let headEle = arr.myShift();
        console.log(tailEle, headEle)
        console.log(arr);


    </script>
</body>

</html>